package cn.ac.iscas.dao.impl;

import cn.ac.iscas.dao.entity.FlinkJobHistoryDO;
import cn.ac.iscas.dao.mapper.IFlinkJobHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author LJian
 * @version 1.0
 * @description: TODO
 * @date 2023/2/2 16:25
 */
@Service
public class FlinkJobHistoryDao {

    @Autowired
    private IFlinkJobHistoryMapper flinkJobHistoryMapper;
    public String getLastestFlinkJobId(String jobId) {
        FlinkJobHistoryDO flinkJobHistory = flinkJobHistoryMapper.selectLatestByJobId(jobId);
        return flinkJobHistory.getFlinkJobId();
    }

    public boolean insert(FlinkJobHistoryDO flinkJobHistoryDO) {
        int res = flinkJobHistoryMapper.insert(flinkJobHistoryDO);
        return res == 1 ? true : false;
    }

    public int selectMaxExecuteCoundByJobId(String jobId){
        return flinkJobHistoryMapper.selectMaxExecuteCoundByJobId(jobId);
    }

    public int selectCountByJobId(String jobId){
        return flinkJobHistoryMapper.selectJobIdCount(jobId);
    }

    public int updateFlinkJobStatus(String flinkJobId, String status) {
        return flinkJobHistoryMapper.updateStatus(flinkJobId, status);
    }

    public int updateFlinkJobStatusDuration(String flinkJobId, String status, Long duration) {
        return flinkJobHistoryMapper.updateStatusDuration(flinkJobId, status, duration);
    }
}
